package com.zmj.sy.mom.srv.aps.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zmj.sy.mom.srv.aps.bean.bo.StationCount;
import com.zmj.sy.mom.srv.aps.bean.entity.resource.Group;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GroupMapper extends SyMapper<Group> {

    @Select("select s.group_id groupId, count(s.group_id) stationCount, g.my_code myCode,g.`name` name , g.seq seq " +
            "from tb_station s " +
            "left join tb_group g on g.id = s.group_id  and g.deleted = 0 " +
            "${ew.customSqlSegment}")
    List<StationCount> findStationCount(@Param(Constants.WRAPPER) QueryWrapper<Group> objectQueryWrapper);
    @Select("select s.group_id groupId, count(s.group_id)* MAX(s.work_ability) stationCount, g.my_code myCode,g.`name` name , g.seq seq " +
            "from tb_station s " +
            "left join tb_group g on g.id = s.group_id  and g.deleted = 0 " +
            "${ew.customSqlSegment}")
    List<StationCount> findStationAbility(@Param(Constants.WRAPPER) QueryWrapper<Group> objectQueryWrapper);

    @Select(" SELECT DISTINCT tg.* from tb_group tg " +
            " INNER JOIN tb_phase_group tpg on tg.my_code=tpg.group_code " +
            " where tpg.phase_code=#{phaseCode}")
    List<Group> selectGroupByPhase(@Param("phaseCode") String phaseCode);
    @Select(" select g.my_code, g.id,g.`name` from tb_station s  " +
            " left join tb_group g on g.id = s.group_id " +
            " where s.id=#{stationId}")
    Group selectGroupByStation(@Param("stationId") Integer stationId);

    @Select("  SELECT" +
            "        distinct tg.my_code" +
            "        FROM" +
            "        tb_station ts" +
            "        LEFT JOIN tb_group tg ON ts.group_id = tg.id" +
            " ${ew.customSqlSegment}")
    Group selectGroupByWorkPlace(@Param(Constants.WRAPPER) QueryWrapper<Group> query);
    @Select(" SELECT tg.* from tb_group tg LEFT JOIN tb_phase_group tpg on tg.my_code=tpg.group_code " +
            "  left join tb_phase tp on tpg.phase_code=tp.my_code " +
            "  where tg.type=2  and tp.workload_show=1  and tg.deleted=0")
    List<Group> selectPhaseList();
}
